package com.yoomiito.app.utils

import android.graphics.Color
import android.graphics.drawable.Drawable
import android.graphics.drawable.GradientDrawable
import android.graphics.drawable.ShapeDrawable
import android.graphics.drawable.StateListDrawable

object ColorUtils {

    fun gradient(colorStart:String,colorEnd:String,orientation:GradientDrawable.Orientation = GradientDrawable.Orientation.LEFT_RIGHT)
            = GradientDrawable(orientation, intArrayOf(Color.parseColor(colorStart), Color.parseColor(colorEnd)))

    fun gradientAndRadius(colorStart:String,colorEnd:String,radius:Float,orientation:GradientDrawable.Orientation = GradientDrawable.Orientation.LEFT_RIGHT):GradientDrawable {
        val drawable = GradientDrawable(orientation, intArrayOf(Color.parseColor(colorStart), Color.parseColor(colorEnd)))
        drawable.cornerRadius = DensityUtil.dp2px(radius).toFloat()
        return drawable
    }

    fun gradientAndRadius(colorStart:String,colorEnd:String,leftTopRadius:Float,rightTopRadius:Float,leftBottomRadius:Float,rightBottomRadius:Float,orientation:GradientDrawable.Orientation = GradientDrawable.Orientation.LEFT_RIGHT):GradientDrawable{
        val drawable = GradientDrawable(orientation, intArrayOf(Color.parseColor(colorStart), Color.parseColor(colorEnd)))
        val leftTop = DensityUtil.dp2px(leftTopRadius).toFloat()
        val rightTop = DensityUtil.dp2px(rightTopRadius).toFloat()
        val leftBottom = DensityUtil.dp2px(leftBottomRadius).toFloat()
        val rightBottom = DensityUtil.dp2px(rightBottomRadius).toFloat()
        drawable.cornerRadii = floatArrayOf(leftTop,leftTop,rightTop,rightTop,rightBottom,rightBottom,leftBottom,leftBottom)
        return drawable
    }

    fun background(colorRes:Int,radius:Float = 0f):GradientDrawable{
        val drawable = GradientDrawable()
        drawable.cornerRadius = DensityUtil.dp2px(radius).toFloat()
        drawable.setColor(ResUtil.getColor(colorRes))
        return drawable
    }

}